#include<at89c51ed2.h>
#include<mcs51reg.h>
#include "spi.h"
#include "sst25vf080b.h"
#include "io.h"
#include <stdio.h>



/*must execute Write Status Register in init for this to work*/
/*working fine at 20:19*/
void writeByte(int addrH,int addrM,int addrL,int TxData)
{
	
	Master_spi_init(2); //for memory  chip*/
	spiChipSelectON(2);
	spi_dataSend(0x50);//enable EWSR (Enable Write Status register)
	spiChipSelectOFF(2);


	spiChipSelectON(2);
	sstDataReadRegisterSet(0x01); //enable WRSR
	spi_dataSend(0x02);//write to write status register, WEL bit should go to zero, expected value 00
	spiChipSelectOFF(2);
	
	
	
	
	//printf("status %x",spi_dataRead(0x05,2));
	
	
	/****WREN enable**/
	spiChipSelectON(2);
	sstDataReadRegisterSet(0x06);//enable WREN, now expected value of WRSR 02
	spiChipSelectOFF(2);
//	
//	/**write byte*******************/

//	
	spiChipSelectON(2);
	sstDataReadRegisterSet(0x02);
	
	spi_dataSend(addrH);
	spi_dataSend(addrM);
	spi_dataSend(addrL);
	
	spi_dataSend(TxData);
	spiChipSelectOFF(2);
	
	
		while((spi_dataRead(0x05,2)&0x01)==1)
	{	
		printf("%x",spi_dataRead(0x05,2));
		
	}
	
	Master_spi_init(1); //for rssi chip,restored*/

}
